/**
 * 
 */

$.ajaxSetup( {
	cache : false
// close AJAX cache
		});
String.prototype.replaceAll = function(s1, s2) {
	return this.replace(new RegExp(s1, "gm"), s2);
}
DetailAll = function() {
	this.member = null;
	this.blood = null;
	this.constellation = null;
	this.profile = null;
	this.introduction = null;
	this.provice = null;
	this.city = null;
	this.district = null;
	this.address = null;
	this.sex = null;
	this.email = null;
	this.zipcode = null;
	this.phone = null;
	this.mobilephone = null;
	this.qq = null;
	this.msn = null;
	this.personalityList = new Array();
	this.contactList = new Array();
}

BabyAll = function() {
	this.babyList = new Array();
	this.babyName = null;
	this.babySex = null;
	this.birthday = null;
}

FamilyAll = function() {
	this.nickname = null;
	this.province = null;
	this.city = null;
	this.district = null;
	this.email = null;
	this.username = null;
	this.role = null;
	this.password = null;
	this.babyList = new Array();
}

Album = function() {
	this.identifier = null;
	this.name = null;
	this.description = null;
	this.place = null;
	this.cover = null;
	this.imageServer = null;
	this.pictureList = new Array();
}

function birthdaySplit(birthday) {
	if (IsNull(birthday)) {
		var a = new Array(3);
		a[0] = '';
		a[1] = '';
		a[2] = '';
		return a;
	}
	return birthday.split("-");
}
/*初始化年
 *  year:jquery 对象
 * */
function yearInit(year) {
	var date = new Date();
	var currentYear = date.getFullYear();
	var yearOption = "";
	yearOption += "<option value=''> 请选择</option>"
	for ( var i = currentYear; i > currentYear - 60; i--) {
		yearOption += "<option value=" + i + "> " + i + "</option>";
	}
	year.empty();
	$(yearOption).appendTo(year);
}
/*初始化月
 *  month:jquery 对象
 * */
function monthInit(month) {
	var monthOption = "";
	monthOption += "<option value=''> 请选择</option>"
	for ( var i = 1; i < 13; i++) {
		var j = "";
		if (i < 10) {
			j = "0" + i;
		} else {
			j = i;
		}
		monthOption += "<option value=" + j + "> " + i + "</option>";
	}
	month.empty();
	$(monthOption).appendTo(month);
}
/*初始化年月日
 *  birthday:jquery 对象，年月日的上一层
 * */
function yearMonthDay(birthday, strBirthday) {
	var year = birthday.find("#year");
	var month = birthday.find("#month");
	var day = birthday.find("#day");
	yearInit(year);
	monthInit(month);
	var str = "";
	str += "<option value=''>请选择</option>"
	for ( var i = 1; i < 32; i++) {
		var j = "";
		if (i < 10) {
			j = "0" + i;
		} else {
			j = i;
		}
		str += "<option value=" + j + "> " + i + "</option>";
	}
	$(str).appendTo(day);

	if (!IsNull(strBirthday)) {
		var a = birthdaySplit(strBirthday);
		year.val(a[0]);
		month.val(a[1]);
		day.val(a[2]);
	}

	month.change(function() {
		var yearstr = year.find("option:selected").val();
		var monthstr = month.find("option:selected").text();
		day.empty();
		var str = "<option value=''>请选择</option>";

		if (monthstr == 1 || monthstr == 3 || monthstr == 5 || monthstr == 7
				|| monthstr == 8 || monthstr == 10 || monthstr == 12) {
			for ( var i = 1; i < 32; i++) {
				var j = "";
				if (i < 10) {
					j = "0" + i;
				} else {
					j = i;
				}
				str += "<option value=" + j + "> " + i + "</option>";
			}
			$(str).appendTo(day);
		} else if (monthstr == 2) {
			day.empty();
			if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0
					&& yearstr % 400 == 0) {
				for ( var i = 1; i < 30; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			} else {
				for ( var i = 1; i < 29; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			}
			$(str).appendTo(day);
		} else {
			day.empty();
			for ( var i = 1; i < 31; i++) {
				var j = "";
				if (i < 10) {
					j = "0" + i;
				} else {
					j = i;
				}
				str += "<option value=" + j + "> " + i + "</option>";
			}
			$(str).appendTo(day);
		}
	});
	year.change(function() {
		var yearstr = year.find("option:selected").val();
		var monthstr = month.find("option:selected").text();
		var str = "";
		if (monthstr == 2) {
			day.empty();
			if (yearstr % 100 != 0 && yearstr % 4 == 0 || yearstr % 100 == 0
					&& yearstr % 400 == 0) {
				for ( var i = 1; i < 30; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			} else {
				for ( var i = 1; i < 29; i++) {
					var j = "";
					if (i < 10) {
						j = "0" + i;
					} else {
						j = i;
					}
					str += "<option value=" + j + "> " + i + "</option>";
				}
			}
			$(str).appendTo(day);
		}
	});
}

/**
 * 时间对象的格式化;
 */
Date.prototype.format = function(format) {
	/*
	 * eg:format="YYYY-MM-dd hh:mm:ss";
	 */
	var o = {
		"M+" : this.getMonth() + 1, // month
		"d+" : this.getDate(), // day
		"h+" : this.getHours(), // hour
		"m+" : this.getMinutes(), // minute
		"s+" : this.getSeconds(), // second
		"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
		"S" : this.getMilliseconds()
	// millisecond
	}

	if (/(y+)/.test(format)) {
		format = format.replace(RegExp.$1, (this.getFullYear() + "")
				.substr(4 - RegExp.$1.length));
	}

	for ( var k in o) {
		if (new RegExp("(" + k + ")").test(format)) {
			format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
					: ("00" + o[k]).substr(("" + o[k]).length));
		}
	}
	return format;
}

function IsNull(i) {
	return (i == null || i == 'null' || i == '' || i == 'undefined');
}
/**
 * 验证提示中文
 * */
jQuery.extend(jQuery.validator.messages, {
	required : "字段不能为空",
	remote : "请修正该字段",
	email : "请输入正确格式的电子邮件",
	url : "请输入合法的网址",
	date : "请输入合法的日期",
	dateISO : "请输入合法的日期 (ISO).",
	number : "请输入合法的数字",
	digits : "只能输入整数",
	creditcard : "请输入合法的信用卡号",
	equalTo : "请再次输入相同的值",
	accept : "请输入拥有合法后缀名的字符串",
	maxlength : jQuery.validator.format("长度不能超过 {0} 字符"),
	minlength : jQuery.validator.format("长度必须大于 {0} 字符"),
	rangelength : jQuery.validator.format("长度在 {0} 和 {1} 之间"),
	range : jQuery.validator.format("值在 {0} 和 {1} 之间"),
	max : jQuery.validator.format("最大值为 {0}"),
	min : jQuery.validator.format("最小值为 {0}")
});
/**
 图片自动缩略宽和高 
 加 $(function(){ $("图片组所在的容器").ImageAutoSize(限制最大宽,限制最大高);});
 */
jQuery.fn.ImageAutoSize = function(width, height) {
	$("img", this).each(function() {
		var image = $(this);
		if (image.width() > width) {
			image.width(width);
			image.height(width / image.width() * image.height());
		}
		if (image.height() > height) {
			image.height(height);
			image.width(height / image.height() * image.width());
		}
	});
}

/**
 只能输入中文
 */
jQuery.validator.addMethod("chinese", function(value, element) {
	var chinese = /^[\u4e00-\u9fa5]+$/;
	return this.optional(element) || (chinese.test(value));
}, "只能输入中文");
/**
	看其他家
*/
function seeOtherFamily(family) {
	window.location = "family?id=" + family;
}


function operateTip(id) {
	$("#" + id).show();
	$("#" + id).fadeOut(4000);
}

function familyTipShow(familyObj, doorplate, addHeight) {
	if (IsNull(addHeight)) {
		addHeight = 62;
	}
	var thisTop = $(familyObj).offset().top;
	var thisLeft = $(familyObj).offset().left;
	$("#family_tip").css("top", thisTop + addHeight);
	$("#family_tip").css("left", thisLeft);
	$("#family_tip").show();
	$("#family_tip").load("familyTip.htm?family=" + doorplate);
}

function familyTipHide(familyObj) {
	$("#family_tip").hide();
}

function showObject(id) {
	$("#" + id).show();
}

function hideObject(id) {
	$("#" + id).hide();
}
///////////////////////////////////////////////////////////////////////////////
//浏览器前进后退功能
function setHash(hash) {
	var localPath = document.location.href;
	if (localPath.lastIndexOf("#") != -1) {
		var localFunctionName = localPath.substring(localPath.lastIndexOf("#"));
		if (!IsNull(localFunctionName) && localFunctionName != '#'
				&& hash == localFunctionName) {
			doHashFunction(localFunctionName);
		}
	}
	location.hash = hash;

}
//浏览器地址改变后执行doHash方法
$(window).hashchange(function() {
	doHash();
});

function doHash() {
	var h = location.hash;
	doHashFunction(h);
}

function doHashFunction(hash) {
	var paras;
	var funName;
	if (!IsNull(hash)) {
		paras = hash.split(',');
		funName = hash.split(',')[0];
	}
	if (!IsNull(funName) && funName != "#") {
		var fun = funName.substring(1);
		var args = "";
		for ( var i = 0; i < paras.length; i++) {
			if (i > 0) {
				args += "'" + decodeURI(paras[i]) + "'";
				if (i != paras.length - 1)
					args += ",";
			}
		}
		eval(fun + "(" + args + ")");
	}

}
///////////////////////////////////////////////////////////////////////////////

//得到客户端页面的高度 
function getTotalHeight() {
	var height = document.body.scrollHeight;
	return height;
}

function getBodyHeight() {
	return $(document).height();
}

function getBodyWidth() {
	return $(document).width();
}
//显示遮罩
function showMask() {
	$("#mask").css("height", getTotalHeight() + "px");
	$("#mask").show();
}

//隐藏遮罩
function hideMask() {
	$("#mask").hide();
}
/**
 日期相加
 * strType：要加的日期是秒，分钟，小时，天数，周数等
 * num：加的数
 * dtTmp：要被加的日期，类型为Date
 */
function dateAdd(strType, num, dtTmp) {
	if (isNaN(dtTmp))
		dtTmp = new Date();
	switch (strType) {
	//秒
	case "s":
		dtTmp = new Date(Date.parse(dtTmp) + (1000 * parseInt(num)));
		break;
	//		分钟
	case "n":
		dtTmp = new Date(Date.parse(dtTmp) + (60000 * parseInt(num)));
		break;
	//		小时
	case "h":
		dtTmp = new Date(Date.parse(dtTmp) + (3600000 * parseInt(num)));
		break;
	//		天数
	case "d":
		dtTmp = new Date(Date.parse(dtTmp) + (86400000 * parseInt(num)));
		break;
	//		周数
	case "w":
		dtTmp = new Date(Date.parse(dtTmp) + ((86400000 * 7) * parseInt(num)));
		break;
	//		月数
	case "m":
		dtTmp = new Date(dtTmp.getFullYear(), (dtTmp.getMonth())
				+ parseInt(num), dtTmp.getDate(), dtTmp.getHours(), dtTmp
				.getMinutes(), dtTmp.getSeconds());
		break;
	//		年数
	case "y":
		dtTmp = new Date(dtTmp.getFullYear() + parseInt(num), dtTmp.getMonth(),
				dtTmp.getDate(), dtTmp.getHours(), dtTmp.getMinutes(), dtTmp
						.getSeconds());
		break;
	}

	return dtTmp;
}

function getWeekDay(date) {
	if (IsNull(date))
		date = new Date();
	var x = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
	return (x[date.getDay()]);
}
/**
 将字符串转换成日期
 * 格式：yyyy-MM-dd hh:mm:ss
 */
function strToDate(str) {
	var strArray = str.split(" ");
	var ymd = strArray[0];
	var ymdArray = ymd.split("-");
	var parseDate = ymdArray[1] + "/" + ymdArray[2] + "/" + ymdArray[0];
	if (!IsNull(strArray[1])) {
		parseDate += " ";
		parseDate += strArray[1];
	}
	var val = Date.parse(parseDate);
	var newDate = new Date(val);
	return newDate;
}

function htmlEncode(str){
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&/g, "&gt;");
	s = s.replace(/</g, "&lt;");
	s = s.replace(/>/g, "&gt;");
	s = s.replace(/ /g, "&nbsp;");
	s = s.replace(/\'/g, "&#39;");
	s = s.replace(/\"/g, "&quot;");
	s = s.replace(/\n/g, "<br>");
	return s;
}

function htmlDecode(str) {
	var s = "";
	if (str.length == 0)
		return "";
	s = str.replace(/&gt;/g, "&");
	s = s.replace(/&lt;/g, "<");
	s = s.replace(/&gt;/g, ">");
	s = s.replace(/&nbsp;/g, " ");
	s = s.replace(/&#39;/g, "\'");
	s = s.replace(/&quot;/g, "\"");
	s = s.replace(/<br>/g, "\n");
	return s;
}

var currentSkin = '';
function setCss(type) {
	$("#home_style").attr("href", type);
	currentSkin = type;
}
